package cn.iocoder.yudao.module.enterprise.controller.admin.emissionbasis;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.enterprise.controller.admin.emissionbasis.vo.EmissionBasisCreateReqVO;
import cn.iocoder.yudao.module.enterprise.controller.admin.emissionbasis.vo.EmissionBasisRespVO;
import cn.iocoder.yudao.module.enterprise.controller.admin.emissionbasis.vo.EmissionBasisUpdateReqVO;
import cn.iocoder.yudao.module.enterprise.service.emissionbasis.EmissionBasisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name =  "管理后台 - 排放基准")
@RestController
@RequestMapping("/enterprise/emission-basis")
@Validated
public class EmissionBasisController {

    @Resource
    private EmissionBasisService emissionBasisService;

    @PostMapping("/create")
    @Operation(summary = "创建排放基准")
    @PreAuthorize("@ss.hasPermission('enterprise:emission-basis:create')")
    public CommonResult<Long> createEmissionBasis(@Valid @RequestBody EmissionBasisCreateReqVO createReqVO) {
        return success(emissionBasisService.createEmissionBasis(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新排放基准")
    @PreAuthorize("@ss.hasPermission('enterprise:emission-basis:update')")
    public CommonResult<Boolean> updateEmissionBasis(@Valid @RequestBody EmissionBasisUpdateReqVO updateReqVO) {
        emissionBasisService.updateEmissionBasis(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除排放基准")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('enterprise:emission-basis:delete')")
    public CommonResult<Boolean> deleteEmissionBasis(@RequestParam("id") Long id) {
        emissionBasisService.deleteEmissionBasis(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得排放基准")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('enterprise:emission-basis:query')")
    public CommonResult<EmissionBasisRespVO> getEmissionBasis(@RequestParam("id") Long id) {
        return success(emissionBasisService.getEmissionBasis(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获得排放基准列表")
    @PreAuthorize("@ss.hasPermission('enterprise:emission-basis:query')")
    public CommonResult<List<EmissionBasisRespVO>> getEmissionBasisList() {
        return success(emissionBasisService.getEmissionBasisList());
    }

}
